home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 February (DVD) / PCWorld_2008-02_DVD.iso / v cisle / PHP / PHP.exe / xampp-win32-1.6.5-installer.exe / phpMyAdmin / tbl_export.php < prev    next >
Encoding:
PHP Script  |  2007-12-20  |  3.8 KB  |  128 lines

  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4.  *
  5.  * @version $Id: tbl_export.php 10240 2007-04-01 11:02:46Z cybot_tm $
  6.  */
  7.  
  8. /**
  9.  *
  10.  */
  11. require_once './libraries/common.inc.php';
  12.  
  13. /**
  14.  * Gets tables informations and displays top links
  15.  */
  16. require_once './libraries/tbl_common.php';
  17. $url_query .= '&goto=tbl_export.php&back=tbl_export.php';
  18. require_once './libraries/tbl_info.inc.php';
  19.  
  20. // Dump of a table
  21.  
  22. $export_page_title = $strViewDump;
  23.  
  24. // When we have some query, we need to remove LIMIT from that and possibly
  25. // generate WHERE clause (if we are asked to export specific rows)
  26.  
  27. if (! empty($sql_query)) {
  28.     // Parse query so we can work with tokens
  29.     $parsed_sql = PMA_SQP_parse($sql_query);
  30.  
  31.     // Need to generate WHERE clause?
  32.     if (isset($primary_key)) {
  33.         // Yes => rebuild query from scracts, this doesn't work with nested
  34.         // selects :-(
  35.         $analyzed_sql = PMA_SQP_analyze($parsed_sql);
  36.         $sql_query = 'SELECT ';
  37.  
  38.         if (isset($analyzed_sql[0]['queryflags']['distinct'])) {
  39.             $sql_query .= ' DISTINCT ';
  40.         }
  41.  
  42.         $sql_query .= $analyzed_sql[0]['select_expr_clause'];
  43.  
  44.         if (!empty($analyzed_sql[0]['from_clause'])) {
  45.             $sql_query .= ' FROM ' . $analyzed_sql[0]['from_clause'];
  46.         }
  47.  
  48.         $wheres = array();
  49.  
  50.         if (isset($primary_key) && is_array($primary_key)
  51.          && count($primary_key) > 0) {
  52.             $wheres[] = '(' . implode(') OR (',$primary_key) . ')';
  53.         }
  54.  
  55.         if (!empty($analyzed_sql[0]['where_clause']))  {
  56.             $wheres[] = $analyzed_sql[0]['where_clause'];
  57.         }
  58.  
  59.         if (count($wheres) > 0) {
  60.             $sql_query .= ' WHERE (' . implode(') AND (', $wheres) . ')';
  61.         }
  62.  
  63.         if (!empty($analyzed_sql[0]['group_by_clause'])) {
  64.             $sql_query .= ' GROUP BY ' . $analyzed_sql[0]['group_by_clause'];
  65.         }
  66.         if (!empty($analyzed_sql[0]['having_clause'])) {
  67.             $sql_query .= ' HAVING ' . $analyzed_sql[0]['having_clause'];
  68.         }
  69.         if (!empty($analyzed_sql[0]['order_by_clause'])) {
  70.             $sql_query .= ' ORDER BY ' . $analyzed_sql[0]['order_by_clause'];
  71.         }
  72.     } else {
  73.         // Just crop LIMIT clause
  74.         $inside_bracket = FALSE;
  75.         for ($i = $parsed_sql['len'] - 1; $i >= 0; $i--) {
  76.             if ($parsed_sql[$i]['type'] == 'punct_bracket_close_round') {
  77.                 $inside_bracket = TRUE;
  78.                 continue;
  79.             }
  80.             if ($parsed_sql[$i]['type'] == 'punct_bracket_open_round') {
  81.                 $inside_bracket = FALSE;
  82.                 continue;
  83.             }
  84.             if (!$inside_bracket && $parsed_sql[$i]['type'] == 'alpha_reservedWord' && strtoupper($parsed_sql[$i]['data']) == 'LIMIT') {
  85.                 // We found LIMIT to remove
  86.  
  87.                 $sql_query = '';
  88.  
  89.                 // Concatenate parts before
  90.                 for ($j = 0; $j < $i; $j++) {
  91.                     $sql_query .= $parsed_sql[$j]['data'] . ' ';
  92.                 }
  93.  
  94.                 // Skip LIMIT
  95.                 $i++;
  96.                 while ($i < $parsed_sql['len'] &&
  97.                     ($parsed_sql[$i]['type'] != 'alpha_reservedWord' ||
  98.                     ($parsed_sql[$i]['type'] == 'alpha_reservedWord' && $parsed_sql[$i]['data'] == 'OFFSET'))) {
  99.                     $i++;
  100.                 }
  101.  
  102.                 // Add remaining parts
  103.                 while ($i < $parsed_sql['len']) {
  104.                     $sql_query .= $parsed_sql[$i]['data'] . ' ';
  105.                     $i++;
  106.                 }
  107.                 break;
  108.             }
  109.         }
  110.     }
  111.     $message = $GLOBALS['strSuccess'];
  112. }
  113.  
  114. /**
  115.  * Displays top menu links
  116.  */
  117. require './libraries/tbl_links.inc.php';
  118.  
  119. $export_type = 'table';
  120. require_once './libraries/display_export.lib.php';
  121.  
  122.  
  123. /**
  124.  * Displays the footer
  125.  */
  126. require_once './libraries/footer.inc.php';
  127. ?>
  128.